package leetcode.每日一题;

import org.junit.Test;

import java.util.Stack;

/**
 * @author ：zsy
 * @date ：Created 2021/6/19 15:32
 * @description：https://leetcode-cn.com/problems/valid-parentheses/
 */
public class 有效的括号 {

    @Test
    public void Test() {
        Solution solution = new Solution();
        System.out.println(solution.isValid("([)]"));
    }

    class Solution {
        public boolean isValid(String s) {
            Stack<Character> stack = new Stack<>();
            for (char c : s.toCharArray()) {
                if (c == '(') {
                    stack.push(')');
                } else if (c == '{') {
                    stack.push('}');
                } else if (c == '[') {
                    stack.push(']');
                } else if (stack.isEmpty() || c != stack.pop())
                    return false;
            }
            return stack.isEmpty();
        }
    }
}
